package com.eatme.web.app.coupon.common.constant;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * 优惠券分类
 */
public enum CouponCategory {
    MANJIAN("满减券","001"),
    ZHEKOU("折扣券","002"),
    LIJIAN("立减券","003");

    /** 优惠券描述(分类) */
    private String description;

    /** 优惠券分类编码 */
    private String code;

    CouponCategory(String description, String code) {
        this.description = description;
        this.code = code;
    }

    public String getDescription() {
        return description;
    }

    public String getCode() {
        return code;
    }

    public static CouponCategory of(String code) {
        Objects.requireNonNull(code);
        return Stream.of(values())
                .filter(bean -> bean.code.equals(code))
                .findAny().
                orElseThrow(() -> new IllegalArgumentException(code + "not exists!"));
    }
}
